package com.dd.common.strategy;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dd.common.strategy.FileStrategy;
import com.dd.pojo.query.UserFileQuery;
import com.dd.pojo.entry.File;
import com.dd.mapper.FileMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * 是否已经上传文件
 */
@Component
@RequiredArgsConstructor
public class FileStrategyUpload implements FileStrategy {

    private final FileMapper fileMapper;
    @Override
    public boolean checkFileUpload(UserFileQuery checks) {

        File file = fileMapper.selectOne(new LambdaQueryWrapper<File>().eq(File::getFileMd5, checks.getFileMd5()));

        if(Objects.isNull(file)){
            return  false;
        }
        return true;
    }
}
